﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;
using System.Data.SqlTypes;


namespace IHISCETeim.DAL
{
    public class OJobJinKouDAL
    {
        public static int Add(string MachineType, string SerialNumber, DateTime DownlineDate)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("OJobJinKou_Add", MachineType, SerialNumber, DownlineDate);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }

        public static DataTable GetAllList()
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("OJobJinKou_GetAllList");
            return DB.ExecuteDataSet(dbCommand).Tables[0];
	    }
        public static int GetSum(string MachineType, int IsInStorage)
        {
            Database DB = DatabaseFactory.CreateDatabase();
            try
            {
                DbCommand dbCommand = DB.GetStoredProcCommand("OJobJinKou_GetSum", MachineType, IsInStorage);
                return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
            }
            catch
            {
                return 0;
            }
        }
        public static bool Update(int Id, DateTime InStorageDate, string WhsCode, bool Status)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("OJobJinKou_Update", Id, InStorageDate, WhsCode, Status);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
